# @File    : connect.py
# @Project : JBL_Android&iOS
# 连接设备类
import subprocess
from airtest.core.api import *

from common.logUtil import info_a


class ConnectUtil:

    dev_android = None
    dev_ios = None
    dev_windows = None

    # 连接Android手机
    def connect_android(self):
        self.dev_android = connect_device("Android:///")
        info_a("已连接到安卓手机")
        return self.dev_android

    def disconnect_android(self):
        disconnect = subprocess.Popen(["adb", "disconnect"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # output, error = disconnect.communicate()
        # print(output)
        info_a("已断开安卓手机连接")

    # 连接ios手机
    def connect_ios(self):
        dev_ios = connect_device("iOS:///127.0.0.1:8100")
        return dev_ios

    # 连接Windows爱思助手
    def connect_windows(self):
        self.dev_windows = connect_device("Windows:///?title_re=爱思助手")
        return self.dev_windows
